// Display.cpp
#include <iostream>
#include "Display.h"

Display::Display(){
}

const std::string Display:: _programName = "Calenzier";	
	
void Display::displayTasks(std::vector<Task> displayList){
	std::stringstream output;
	int counter = 1;

	for(std::vector<Task>::iterator iter = displayList.begin(); iter != displayList.end();){
		//Numbering
		output << counter << ". ";
		counter++;
		//Task Description
		output << iter->getTaskDesc();
		//Date
		output  << " on " << iter->getDay() << "/" << iter->getMonth() << "/" << iter->getYear();
		//Time
		output << " from " << iter->getStartTime() << " to " << iter->getEndTime() << "\n";
		iter++;
	}
	std::cout << output.str();
}

const std::string Display::MSG_WELCOME = "Welcome to %s. It is ready for use";
const std::string Display::MSG_USERPROMPT= "command: ";
const std::string Display::MSG_ADD_SUCCESS ="added to %s: \"%s\"";
const std::string Display::MSG_EDIT_SUCCESS ="%s updated";
const std::string Display::MSG_DELETE_SUCCESS ="deleted from %s: \"%s\"";
const std::string Display::MSG_UNDO_SUCCESS ="latest change to %s undone";
const std::string Display::MSG_REDO_SUCCESS ="latest undo to %s reverted";
const std::string Display::MSG_COMPLETE_SUCCESS ="%S marked as complete";

const std::string Display::MSG_INVALID_CMD = "invalid command";
const std::string Display::MSG_INVALID_LINENO = "invalid line";
const std::string Display::MSG_INVALID_TIME = "invalid time";
const std::string Display::MSG_INVALID_DATE = "invalid date";

const std::string Display::MSG_NOT_FOUND ="\"%s\" not found in %s";
const std::string Display::MSG_EMPTY_FILE = "%s is empty";
const std::string Display::DELIMITER =". ";

void Display::displayUI(std::string output) {
	std::cout << output;

	//no newline after "command: "
	if(output != MSG_USERPROMPT){
		std::cout << std::endl;
	}
}

std::string Display::emptyFeedback() {
	sprintf_s(buffer, MSG_EMPTY_FILE.c_str(), _programName.c_str());
	return buffer;
}

std::string Display::deleteFeedback(std::string removedContent) {
	sprintf_s(buffer, MSG_DELETE_SUCCESS.c_str(), _programName.c_str(), removedContent.c_str());
	return buffer;
}

std::string Display::addFeedback(std::string userInput) {
	sprintf_s(buffer, MSG_ADD_SUCCESS.c_str(), _programName.c_str(), userInput.c_str());
	return buffer;
}

std::string Display::invalidFeedback(){
	sprintf_s(buffer, MSG_INVALID_CMD.c_str());
	return buffer;
}

std::string Display::notFoundFeedback(std::string userInput){
	sprintf_s(buffer, MSG_NOT_FOUND.c_str(), userInput.c_str(), _programName.c_str());
	return buffer;
}

std::string Display::welcomeMsg(){
	sprintf_s(buffer, MSG_WELCOME.c_str(), _programName.c_str());
	return buffer;
}

std::string Display::undoFeedback(){
	sprintf_s(buffer, MSG_UNDO_SUCCESS.c_str(), _programName.c_str());
	return buffer;
}

std::string Display::redoFeedback(){
	sprintf_s(buffer, MSG_REDO_SUCCESS.c_str(), _programName.c_str());
	return buffer;
}

std::string Display::invalidTimeFeedback(){
	sprintf_s(buffer, MSG_INVALID_TIME.c_str());
	return buffer;
}

std::string Display::invalidDateFeedback(){
	sprintf_s(buffer, MSG_INVALID_DATE.c_str());
	return buffer;
}

std::string Display::completeFeedback(std::string userInput){
	sprintf_s(buffer,  MSG_COMPLETE_SUCCESS.c_str(), userInput.c_str());
	return buffer;
}

std::string Display::editFeedback(std::string userInput){
	sprintf_s(buffer, MSG_EDIT_SUCCESS.c_str(), userInput.c_str());
	return buffer;
}
